% ************************************************************************ 
%     Module name   : Lynx Simulation - Aquisition Mode Run                                                     
%                                                                          
%     Description   : This will run the Aquisition mode on a specific target.                                                    
%                                                                          
%     $Header: /Lynx/SimulationFramework/RSP/IFS/IFSRun.m 2     15/10/08 16:08 Lwabeke $ 
%                                                                          
%    $Author: Lwabeke $	            
%                                                                         
%    $Revision: 2 $                
%                                                                         
% ************************************************************************
%     $History: IFSRun.m $ 
% 
%
% ************************************************************************
function  [visualiseState] = visualise(currentTime, radarState, worldState, visualiseState, param)

if (~isstruct(visualiseState))
    visualiseState.time = currentTime;
    visualiseState.radarNumTargets = radarState.TargetList.numTargets;
    visualiseState.worldNumTargets = worldState.activeTargets;
    visualiseState.lastPlot = currentTime;
    visualiseState.radarNumTargets = radarState.TargetList.numTargets;
    visualiseState.targetVisit = radarState.targetVisit - 1;            % Last entry is just to complete scan, not a real target
%    visualiseState.chosen_action = radarState.searchSetup.chosen_action;
else
    visualiseState.time(end+1) = currentTime;
    visualiseState.radarNumTargets(end+1) = radarState.TargetList.numTargets;
    visualiseState.worldNumTargets(end+1) = worldState.activeTargets;
    visualiseState.targetVisit(end+1) = radarState.targetVisit  - 1;    % Last entry is just to complete scan, not a real target
%    visualiseState.chosen_action(end+1) = radarState.searchSetup.chosen_action;
end

% if (radarState.TargetList.numTargets > 0)
%     visualiseState.radarT1RangeEst(size(visualiseState.time)) = radarState.TargetList.Targets(1).RangeEstStd;
% else
%     visualiseState.radarT1RangeEst(size(visualiseState.time)) = NaN;
% end

if (param.display.trackHistory > 0)&&(currentTime - visualiseState.lastPlot > param.display.trackHistory)
    
    figure(1)
%    subplot(2,1,1)
%    plot(visualiseState.time, visualiseState.radarNumTargets,'.-r');
    plot(visualiseState.time, visualiseState.targetVisit,'.-r');
    hold on;
    plot(visualiseState.time, visualiseState.worldNumTargets,'.-');
    hold off;
    title('Targets and Visited Targets per Scan')

%     subplot(2,1,2)
% %    plot(visualiseState.time, visualiseState.radarT1RangeEst,'.-r');
%     plot(visualiseState.time, visualiseState.chosen_action,'.-r');

    visualiseState.lastPlot = currentTime;

    figure(2)
    for cntr = 1:worldState.activeTargets  %radarState.TargetList.numTargets
%         plot(worldState.Target(radarState.TargetList.Targets(cntr).id).currentPos(1), worldState.Target(radarState.TargetList.Targets(cntr).id).currentPos(2), 'g.')
        plot(worldState.Target(cntr).currentPos(1), worldState.Target(cntr).currentPos(2), 'g.')
        hold on;
    end
    title('Target tracks')
    axis(param.world.area)
    drawnow
end


